package com.sichem.infrastructure.dcc;

import com.sichem.types.annotations.DCCValue;
import org.springframework.stereotype.Service;

/**
 * @Author xiangshizhen
 * @Date 2025/3/6
 */

@Service
public class DCCService {

    @DCCValue("downgradeSwitch:0")
    private String downgradeSwitch;

    @DCCValue("cutRange:100")
    private String cutRange; // 切量

    public boolean isDowngradeSwitch() {
        return "1".equals(downgradeSwitch);
    }

    public boolean isCutRange(String userId) {
        // 计算哈希码的绝对值
        int hashCode = Math.abs(userId.hashCode());
        // 获取最后两位
        int lastTwoDigits =  hashCode % 100;
        // 判断是否在切量范围内
        return lastTwoDigits <= Integer.parseInt(cutRange);
    }

}
